<?php
namespace app\index\controller;
use think\Controller;



/*
 *  帖子列表
 */
 
class Notelist extends Controller
{
    public function index($id)
    {
    	// 二级分类查询
        $cate = db('cate')->field('id,catename,pid')->where('id', $id)->find();
        // 一级分类 标题
        $first = db('cate')->field('id,catename')->where('id',$cate['pid'])->find();
        // 普通帖子查询
    	$note = db('note')->where(['cateid'=> $id,'type'=>'0','status'=>'0'])->order('id','desc')->select();
        foreach ($note as &$val) {
            $val['name'] = db('information')->where('userid', $val['uid'])->find()['name'];
            $val['time'] = date('y-m-d h:i',$val['time']);
        }
        // 精华(essence) 帖子查询
        $ess = db('note')->where(['cateid'=> $id,'type'=>'1','status'=>'0'])->order('id','desc')->select();
        foreach ($ess as &$val) {
            $val['name'] = db('information')->where('userid', $val['uid'])->find()['name'];
            $val['time'] = date('y-m-d h:i',$val['time']);
        }
        // var_dump($ess);die;
        // 此区中所有帖子
        $notenum = db('note')->where(['cateid'=>$id,'status'=>'0'])->count('*');

        // 所有版主查询
        $banzhu = db('information')->field('userid,name')->where('type',2)->select();
        $this->assign("banzhu",$banzhu);

        $this->assign('cate',$cate);
        $this->assign('note',$note);
        $this->assign('ess',$ess);
        $this->assign('first',$first);
        $this->assign('notenum',$notenum);
        return $this->fetch();
    }
}
